[MTR04] W2 D14 練習四:請寫出一個叫做 star 的 function 並且接受一個參數 n,能回傳 n 個 *。


Posted by Christy on 2020-07-18

請寫出一個叫做 star 的 function 並且接受一個參數 n,能回傳 n 個 *。

star(1) 會回傳一個 *

star(5) 會回傳五個 *

所以 console.log(star(5)) 的預期輸出是:
五個 *

function star(n){
    var a = ""
    for (i = 1; i<=n; i++){
        a = a + "*"
    } 
    return a
   }  
   console.log(star(3))









Related Posts

Command Line

Command Line

淺談產品開發與工作流程

淺談產品開發與工作流程

Day 03:  GraphQL and GiHub GrapQL - Operations, Variables, and Mutations

Day 03: GraphQL and GiHub GrapQL - Operations, Variables, and Mutations


Comments